package com.lixueju.security.box.validate.code.sms;

import com.lixueju.security.box.core.properties.SecurityBoxProperties;
import com.lixueju.security.box.validate.code.ValidateCode;
import com.lixueju.security.box.validate.code.ValidateCodeGenerator;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 短信验证码生成器
 * @author lixueju
 * @since 2019/10/4 11:27
 **/
@Component
public class SmsValidateCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SecurityBoxProperties securityBoxProperties;
    @Override
    public ValidateCode generate(ServletWebRequest request) {
        String code = RandomStringUtils.randomNumeric(securityBoxProperties.getCode().getSms().getLength());
        return new ValidateCode(code, securityBoxProperties.getCode().getSms().getExpireIn());
    }
}
